package com.example.youxiang;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.springframework.beans.factory.annotation.Value;

/**
 * @Author:郭
 * @Description: TODO
 * @Date: 2022/12/19 14:49
 * @ClassName EmailUtil
 */
public class EmailUtil {
    @Value("spring.mail.from")
    private String from;
    public void sendMessage(String to, String subject, String content) {
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.163.com");
        email.setCharset("utf-8");
        try {
            email.addTo(to);
            email.setFrom(from,"郭");
            email.setAuthentication("a1045295788@163.com ","KEFUFJRZERJTXRND");
            email.setSubject(subject);
            email.setMsg(content);
            email.send();
        }catch (EmailException e){
            e.printStackTrace();
        }
    }
}
